package com.hwod;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.concurrent.atomic.AtomicStampedReference;

/**
 * 求符合条件元组个数
 */
public class Hwod2 {

    public static int[] applyData;
    public static int[] tempIndex;
    public static int[] tempData;
    public static List<int[]> result = new ArrayList<>();
    public static int k;
    public static int target;

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String[] input = in.nextLine().split(" ");
        k = Integer.parseInt(in.nextLine());
        target = Integer.parseInt(in.nextLine());

        applyData = new int[input.length];
        tempIndex = new int[input.length];
        tempData = new int[input.length];
        for (int i = 0; i < input.length; i++) {
            try {
                applyData[i] = Integer.parseInt(input[i]);
            } catch (NumberFormatException e) {
            }
            tempIndex[i] = -1;
        }

        // 对数据排序
        Arrays.sort(applyData);
        System.out.println(Arrays.toString(applyData));

        dfs(0, 0);

        System.out.println(result.size());

        applyData = null;
        tempIndex = null;
        tempData = null;
        result.clear();

        AtomicStampedReference<User> atomicReference = new AtomicStampedReference<>(
                new User("Minla", 20), 1);
        int[] stamp = new int[1];
        User currUser = atomicReference.get(stamp);
        System.out.println(Arrays.toString(stamp) + " --- " + currUser);

        User newUser = new User("Minla", 33);
        atomicReference.compareAndSet(currUser, newUser, stamp[0], stamp[0] + 1);

        currUser = atomicReference.get(stamp);
        System.out.println(Arrays.toString(stamp) + " --- " + currUser);
    }

    public static class User{
        public String name = "";
        public int age = -1;
        public User(String name, int age) {
            this.name = name;
            this.age = age;
        }

        @Override
        public String toString() {
            return "User{" +
                    "name='" + name + '\'' +
                    ", age=" + age +
                    '}';
        }
    }

    public static void dfs(int p, int count) {
        if (count > k) {
            return;
        }
        int tempSum = 0;
        for (int i = 0; i < count; i++) {
            tempSum += tempData[i];
            if (tempSum > target) {
                return;
            }
            if (tempSum == target && i == (k - 1)) { // 正好是k个元素相加为目标才行
                int[] ans = Arrays.copyOfRange(tempData, 0, k);
                Arrays.sort(ans);
                boolean needAdd = true; // 判断是否已经有重复答案，有的话不再添加
                for (int j = 0; j < result.size(); j++) {
                    int[] item = result.get(j);
                    for (int l = 0; l < item.length; l++) {
                        if (item[l] != ans[l]) {
                            break;
                        }
                        if (item[l] == ans[l] && l == item.length - 1) {
                            needAdd = false;
                        }
                    }
                    if (!needAdd) {
                        break;
                    }
                }

                if (needAdd) {
                    result.add(ans);
                }
                return;
            }
        }
        int i = 0;
        if (p > 0 && tempIndex[p - 1] != -1) {
            i = tempIndex[p - 1] + 1;
        }
        for (; i < applyData.length; i++) {
            tempData[p] = applyData[i];
            tempIndex[p] = i;
            dfs(p + 1, count + 1);
        }
    }

}
